<?php
header("Content-type: text/html; charset=utf-8");
/**
 * [商网通 System] Copyright swtshop.cn
 * QQ: 1170787711
 * Author: gj.name
 * This is NOT a freeware
*/
defined('IN_UQ') or exit('Access Denied');
class seller_uqcms extends control
{
    function index()
    {
        $arr =  $this->db->get_all("select * from " . table('fbxq') . " where tbzt = 0 order by addtime desc");
        foreach ($arr as $key => $value){
           $goods = unserialize($value['goods_guige']);
           $guige = '';
           foreach ($goods as $g_value){
               foreach ($g_value as $g_k => $g_v){
                   if($g_k == 0){
                       $guige .= '<a class="guige">'.$g_v.'：</a>';
                   }else{
                       $guige .= $g_v;
                   }
               }
           }
           $arr[$key]['goods_guige'] = $guige;
        }
        $this->assign('arr',$arr);
        $this->display();
    }
    function goods()
    {
        $id = $_GET['fid'];
        if(!empty($id)){
            $sql = "select f.*,u.nick,c.name from " . table('fbxq') . " as f left join ".table('member')." as u on f.user_id = u.uid left join ".table('category')." as c on f.goods_fl = c.cid where id = '{$id}' limit 1";
            $detail = $this->db->get_one($sql);
            $detail['goods_guige'] = unserialize($detail['goods_guige']);

            $this->assign('detail',$detail);
        }else{
            showmsg('买家已取消！');
            header("Location:index.php?m=seller");
        }
        $this->display();
    }
    function add_form()
    {
        if($_POST){
            $tb_id = $_POST['tb_id'];
            $remark = trim($_POST['remark']);
            $price = trim($_POST['price']);
            $shop = $_SESSION['shop']['spid'];
            $user_id = $this->db->get_one("select uid from " . table('shop') . " where id = '{$shop}' limit 1");
            $_SESSION['user']['user_id'] = $user_id['uid'];
            $mid = $user_id['uid'];
            $add = array(
                'mid' => $mid,
                'tb_id' => $tb_id,
                'mjbz' => $remark,
                'money' => $price,
                'iscg' => 0
            );
            $seller_add = $this->db->add(table('tb'), $add);
            if($seller_add){
                $tbs = $this->db->get_one("select tbs from " . table('fbxq') . " where id = '{$tb_id}' limit 1");
                $this->db->update(table('fbxq'), array('tbs' => $tbs['tbs']+1), 'id = ' . $tb_id);
                header("Location:index.php?m=seller");
                showmsg('投标成功！');
            }else{
                showmsg('投标失败！');
            }
        }
        header("Location:index.php?m=seller&a=goods");
    }
}